<template>
  <h1>循环指令</h1>
  <ul>
    <!--v-for:重复执行15次，生成15个li，里面的数字是1-15-->
    <li v-for="item in 15">{{item}}</li>

  </ul>
  <ul>
    <li v-for="p in productArr">{{p}}</li>
  </ul>
  <table border="1px">
    <thead>
      <tr>
        <th>序号</th>
        <th>标题</th>
        <th>价格</th>
        <th>库存</th>
        <th>操作</th>
      </tr>
    <tr v-for = "(item,index) in productArr">
      <td>{{index+1}}</td>
      <td>{{item.title}}</td>
      <td>{{item.price}}</td>
      <td>{{item.num}}</td>
      <td><button @click="del">删除</button></td>
    </tr>
    </thead>
  </table>
</template>

<script setup>
import {ref} from "vue";

const productArr = ref([
  {title:'苹果',price:66,num:12},
  {title:'香蕉',price:45,num:28},
  {title:'葡萄',price:88,num:12},
  {title:'桃子',price:68,num:32}
])
const del = (i)=>{
  if(confirm('您确认要删除吗?')){
    productArr.value.splice(i,1);/*修改 productArr 数组，删除索引为 i 的元素*/
  }
}
</script>


<style scoped>

</style>